package com.anyext.storage;

import java.util.List;
import java.util.Map;

import com.anyext.storage.jdbc.ConnectionCallback;
import com.anyext.storage.jdbc.ResultSetExtractor;
import com.anyext.storage.jdbc.RowCallbackHandler;
import com.anyext.storage.jdbc.RowMapper;

public interface JdbcTemplate {

	// -------------------------------------------------------------------------
	// Methods dealing with a plain java.sql.Connection
	// -------------------------------------------------------------------------

	<T> T execute(ConnectionCallback<T> action) throws SessionException;

	// -------------------------------------------------------------------------
	// Methods dealing with static SQL (java.sql.Statement)
	// -------------------------------------------------------------------------

	void execute(final String sql) throws SessionException;

	<T> T query(String sql, ResultSetExtractor<T> rse) throws SessionException;

	void query(String sql, RowCallbackHandler rch) throws SessionException;

	<T> List<T> query(String sql, RowMapper<T> rowMapper) throws SessionException;

	<T> T queryForObject(String sql, RowMapper<T> rowMapper) throws SessionException;

	<T> T queryForObject(String sql, Class<T> requiredType) throws SessionException;

	Map<String, Object> queryForMap(String sql) throws SessionException;

	List<Map<String, Object>> queryForList(String sql) throws SessionException;

	<T> List<T> queryForList(String sql, Class<T> requiredType) throws SessionException;

	int[] batchUpdate(String[] sql) throws SessionException;

	// -------------------------------------------------------------------------
	// Methods dealing with prepared statements
	// -------------------------------------------------------------------------

	<T> T query(String sql, Object[] args, int[] argTypes, ResultSetExtractor<T> rse) throws SessionException;

	<T> T query(String sql, Object[] args, ResultSetExtractor<T> rse) throws SessionException;

	<T> T query(String sql, ResultSetExtractor<T> rse, Object... args) throws SessionException;

	void query(String sql, Object[] args, int[] argTypes, RowCallbackHandler rch) throws SessionException;

	void query(String sql, Object[] args, RowCallbackHandler rch) throws SessionException;

	void query(String sql, RowCallbackHandler rch, Object... args) throws SessionException;

	<T> List<T> query(String sql, Object[] args, int[] argTypes, RowMapper<T> rowMapper) throws SessionException;

	<T> List<T> query(String sql, Object[] args, RowMapper<T> rowMapper) throws SessionException;

	<T> List<T> query(String sql, RowMapper<T> rowMapper, Object... args) throws SessionException;

	<T> T queryForObject(String sql, Object[] args, int[] argTypes, RowMapper<T> rowMapper) throws SessionException;

	<T> T queryForObject(String sql, Object[] args, RowMapper<T> rowMapper) throws SessionException;

	<T> T queryForObject(String sql, RowMapper<T> rowMapper, Object... args) throws SessionException;

	<T> T queryForObject(String sql, Object[] args, int[] argTypes, Class<T> requiredType) throws SessionException;

	<T> T queryForObject(String sql, Object[] args, Class<T> requiredType) throws SessionException;

	<T> T queryForObject(String sql, Class<T> requiredType, Object... args) throws SessionException;

	Map<String, Object> queryForMap(String sql, Object[] args, int[] argTypes) throws SessionException;

	Map<String, Object> queryForMap(String sql, Object... args) throws SessionException;

	<T> List<T> queryForList(String sql, Object[] args, int[] argTypes, Class<T> requiredType) throws SessionException;

	<T> List<T> queryForList(String sql, Object[] args, Class<T> requiredType) throws SessionException;

	<T> List<T> queryForList(String sql, Class<T> requiredType, Object... args) throws SessionException;

	List<Map<String, Object>> queryForList(String sql, Object[] args, int[] argTypes) throws SessionException;

	List<Map<String, Object>> queryForList(String sql, Object... args) throws SessionException;

	int update(String sql, Object[] args, int[] argTypes) throws SessionException;

	int update(String sql, Object... args) throws SessionException;

	int[] batchUpdate(String sql, List<Object[]> batchArgs);

	int[] batchUpdate(String sql, List<Object[]> batchArgs, int[] argTypes);

}
